<template>
  <div class="order-container">
    <template>
      <el-table :data="orderData" border style="width: 100%">
        <el-table-column prop="orderDetail" label="产品图片" align="center">
          -->
          <!-- 插槽作用域 -->
          <template v-slot="scope">
            <el-avatar
              shape="square"
              :size="80"
              fit="scale-down"
              :src="scope.row.orderDetail[0].imageUrl"
            ></el-avatar>
          </template>
          -->
        </el-table-column>
        <el-table-column prop="order_id" label="订单编号" align="center">
        </el-table-column>
        <el-table-column
          prop="orderDetail[0].productName"
          label="产品名称"
          width="100"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="orderDetail[0].quantity"
          align="center"
          label="数量"
          width="60px"
        >
        </el-table-column>
        <el-table-column prop="total_fee" width="100px" align="center" label="总价格">
        </el-table-column>
        <el-table-column prop="create_time" label="创建时间" width="180px" align="center">
        </el-table-column>
        <el-table-column
          prop="order_status"
          label="支付状态"
          width="100px"
          align="center"
        >
          <template v-slot="{ row }">
            {{ row.pay_status === 1 ? "已支付" : "未支付" }}
          </template>
        </el-table-column>
        <el-table-column
          prop="order_status"
          label="订单状态"
          width="100px"
          align="center"
        >
          <template v-slot="{ row }">
            <span v-if="row.order_status == 0">未提交</span>
            <span v-else-if="row.order_status == 1">交易成功</span>
            <span v-else-if="row.order_status == 2">已经取消</span>
            <span v-else-if="row.order_status == 3">无效订单</span>
            <span v-else-if="row.order_status == 4">交易关闭</span>
            <span v-else-if="row.order_status == 5">退货</span>
          </template>
        </el-table-column>
        <el-table-column prop="opration" label="操作" align="center">
          <template v-slot="{ row }">
            <el-button
              v-hasPay="[row.pay_status, row.order_status]"
              type="primary"
              class="btn"
              icon="el-icon-view"
              @click="pyStu(row)"
              v-has="'read'"
              >去支付</el-button
            >
            <el-button
              type="danger"
              class="btn"
              icon="el-icon-delete"
              @click="deleteStu(row)"
              v-has="'delete'"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </template>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
export default {
  directives: {
    hasPay: {
      inserted(el, binding) {
        //   console.log(binding);
        //指令接受的是用户的支付状态
        //0未支付 显示支付按钮
        //1已支付 禁用支付按钮
        //接收到的参数是一个数组  [pay_status,order_status]
        let [pay_status, order_status] = binding.value;
        // console.log(binding);
        //先保存当前按钮的类名
        let className = el.className;
        //当pay_status不是0，order_status不是1的时候
        //禁用按钮
        //order_status 0未提交 1未提交 2已经取消 3无效订单 4.交易关闭 5退货
        if (pay_status !== 0 || order_status !== 1) {
          //只要状态不为0就不能支付
          el.disabled = true; //禁用按钮
          el.className = className + " " + "is-disabled";
        }
      },
    },
  },
  computed: {
    ...mapState(["orderData"]),
  },
  methods: {
    ...mapActions(["GET_ORDER_DATA"]),
  },
  created() {
    this.GET_ORDER_DATA();
  },
  data() {
    return {};
  },
};
</script>

<style scoped lang="less">
.el-avatar {
  /deep/ img {
    width: 100%;
  }
  background-color: #fff;
}
</style>
